(defun c:keyorder ()
  (setq vpkeystr (ukword 1 "Section Level PHase PLan Alternate Elevation XSection XLevel XPHase XPLan XAlternate XElevation" "Enter CLG user key type to reorder [Alternate/Elevation/Level/PHase/PLan/Section/XX/XAlternate/XElevation/XLevel/XPHase/XPLan/XSection]" vpkeystr))
  (COND
    ((EQ vpkeystr "Alternate")(SETQ vpkey "AL"))
    ((EQ vpkeystr "Elevation")(SETQ vpkey "EL"))
    ((EQ vpkeystr "Level")(SETQ vpkey "LV"))
    ((EQ vpkeystr "PHase")(SETQ vpkey "PH"))
    ((EQ vpkeystr "PLan")(SETQ vpkey "PL"))
    ((EQ vpkeystr "Section")(SETQ vpkey "SC"))
  )
  (setq reorderstr (ustr 1 (STRCAT vpkeystr " range to reorder (front first, back last)") reorderstr T))
  (SETQ keyprefix "*")
  (IF (AND (eq(type(read (substr reorderstr 3)))'INT)(eq(type(read reorderstr))'INT))
    (SETQ reorder_begin (READ reorderstr)
          reorder_end (READ (substr reorderstr 3))
    )
    (SETQ reorder_begin NIL
          reorder_end NIL
    )
  )
  (IF (AND reorder_begin reorder_end (< reorder_begin 100)(< reorder_end 100))
    (PROGN
      (SETQ reorder_ndx reorder_end
            reorder_cnt (abs (- reorder_end reorder_begin))
            reorder_sign (IF (> reorder_end reorder_begin) 1- 1+)
      )
      (WHILE (>= reorder_cnt 0)
        (SETQ layer_srchstr (strcat keyprefix vpkey (IF(< reorder_ndx 10) "0" "") (itoa reorder_ndx) "*"))
        (setq key_ss (ssget "x" (LIST (CONS 8 layer_srchstr))))
;;;        (princ "\nlayer_srchstr = ")
        (PRINC "\nLayer selection = ")
        (PRINC layer_srchstr)
        (IF key_ss
          (PRINC "; FOUND SELECTION")
          (PRINC "; NO SELECTION FOUND! ")
        )
        (PRINC)
        (command ".draworder" key_ss "" "f")
        (IF key_ss
          (PROGN
            (PRINC "; Set selection draworder to 'front'. ")
          )
        )
        (SETQ reorder_ndx (reorder_sign reorder_ndx)
              reorder_cnt (1- reorder_cnt)
        )
      )
    )
    (PROGN
      (PRINC (STRCAT "\nEnter the " vpkeystr " number range separated by a space (front number first, numbers < 100). "))
      (PRINC)
    )
  )
  (PRINC)
)